*** Do File for Main Paper - Unions and White Partisanship ***

*** You will need to change the working directory in order to run this code ***

*** Figure 1 - Trends over time ***
clear
use "C:\Users\dmac9\Dropbox\Accepted Pol Behavior Unions and White Partisanship\two year white party ID and union membership.dta"

twoway line Democrat Union year
*I then manipulate the colors and axes manually through the graph editor

*** Table 1 - Average pooled effects ***
clear
use "C:\Users\dmac9\Dropbox\Accepted Pol Behavior Unions and White Partisanship\ANES cdf.dta"

reg dem_pid union_household female married own_home i.age_group4 i.educ4 i.income_cat i.church_attend i.religion_group i.region i.year [pweight=weight ] if white==1 
outreg2 using tab.tex, dec(3) sideway replace
reg ft_Dem_minus_Rep_Party union_household female married own_home i.age_group4 i.educ4 i.income_cat i.church_attend i.religion_group i.region i.year [pweight=weight ] if white==1
outreg2 using tab.tex, dec(3) sideway append

*** Table 2 - Split up by union members, household only, and non union ***
reg dem_pid i.union_status female married own_home i.age_group4 i.educ4 i.income_cat i.church_attend i.religion_group i.region i.year [pweight=weight ] if white==1 
outreg2 using tab.tex, dec(3) sideway replace
reg ft_Dem_minus_Rep_Party i.union_status female married own_home i.age_group4 i.educ4 i.income_cat i.church_attend i.religion_group i.region i.year [pweight=weight ] if white==1
outreg2 using tab.tex, dec(3) sideway append

*** Figure 2 - Union household effects over time ***
clear
use "C:\Users\dmac9\Dropbox\Accepted Pol Behavior Unions and White Partisanship\ANES cdf.dta"

*Unions and Democratic ID by decade - ANES*
probit Democrat union_household [pweight=weight] if white==1 & mode==0 & (year==1964|year==1968)
margins, dydx(union_household) saving(m60s, replace)

probit Democrat union_household [pweight=weight] if white==1 & mode==0 & (year==1972|year==1976)
margins, dydx(union_household) saving(m70s, replace)

probit Democrat union_household [pweight=weight] if white==1 & mode==0 & (year==1980|year==1984|year==1988)
margins, dydx(union_household) saving(m80s, replace)

probit Democrat union_household [pweight=weight] if white==1 & mode==0 & (year==1992|year==1996)
margins, dydx(union_household) saving(m90s, replace)

probit Democrat union_household [pweight=weight] if white==1 & mode==0 & (year==2000|year==2004|year==2008)
margins, dydx(union_household) saving(m00s, replace)

probit Democrat union_household  [pweight=weight] if white==1 & mode==0 & (year==2012|year==2016)
margins, dydx(union_household) saving(m10s, replace)

*** Table 3 - Jennings Panel Study Tracking adults unionization and party ID ***
clear
use "C:\Users\dmac9\Dropbox\Accepted Pol Behavior Unions and White Partisanship\ICPSR4037 panel.dta" 

reg dem_pid_97 Adulthood_unionhh if Race==1, r
outreg2 using tab.tex, dec(3) sideway replace

reg dem_pid_97 Adulthood_unionhh dem_pid_65 if Race==1, r
outreg2 using tab.tex, dec(3) sideway replace

*** Figure 3 - Aggregate Reverse causality  ***
clear
use "C:\Users\dmac9\Dropbox\Accepted Pol Behavior Unions and White Partisanship\two year white party ID and union membership.dta"

reg Union lag_Democrat lag_Union, r
margins, dydx(lag_Democrat) saving(m_lag_dem, replace)

reg Democrat lag_Union lag_Democrat, r 
margins, dydx(lag_Union) saving(m_lag_union, replace)

combomarginsplot m_lag_dem m_lag_union, horizontal

*** Figure 4 - Jennings Panel Study party ID and joining a union ***
clear
use "C:\Users\dmac9\Dropbox\Accepted Pol Behavior Unions and White Partisanship\ICPSR4037 panel.dta" 

probit joined_union_73_82 c.Democrat73##c.RTW82  if Race ==1 & (Same_RTW_73_82 ==1) & (state73!=45 & state82!=45), r
margins, dydx(Democrat73) at(RTW82=(0(1)1))
marginsplot

*** Table 4 - CCES Panel 2010-2012 Cross Tabs ***
clear
use "C:\Users\dmac9\Dropbox\Accepted Pol Behavior Unions and White Partisanship\CCES 2010 and 2012 panel.dta" 

tab entered_union_10_12 if Race==1 & (RTW_10==RTW_12) & (inputstate_10!=18 & inputstate_12!=18) & Democrat_2010==1
tab entered_union_10_12 if Race==1 & (RTW_10==RTW_12) & (inputstate_10!=18 & inputstate_12!=18) & Democrat_2010==0

tab entered_union_10_12 if Race==1 & (RTW_10==RTW_12) & (inputstate_10!=18 & inputstate_12!=18) & Democrat_2010==1 & RTW_12==0  
tab entered_union_10_12 if Race==1 & (RTW_10==RTW_12) & (inputstate_10!=18 & inputstate_12!=18) & Democrat_2010==0 & RTW_12==0

tab entered_union_10_12 if Race==1 & (RTW_10==RTW_12) & (inputstate_10!=18 & inputstate_12!=18) & Democrat_2010==1 & RTW_12==1
tab entered_union_10_12 if Race==1 & (RTW_10==RTW_12) & (inputstate_10!=18 & inputstate_12!=18) & Democrat_2010==0 & RTW_12==1

*** Table 5 - Pooled CCES 2006-2012 Mean Differences ***
clear
use "C:\Users\dmac9\Dropbox\Accepted Pol Behavior Unions and White Partisanship\pooled CCES 2006 to 2012.dta"

*Private Sector*
mean Democrat [pweight=weight] if White==1 & Private_Sector==1 & Union_Member_Status==3 
mean Democrat [pweight=weight] if White==1 & Private_Sector==1 & Union_Member_Status==1

*Public Sector*
mean Democrat [pweight=weight] if White==1 & Public_Sector==1 & Union_Member_Status==3 
mean Democrat [pweight=weight] if White==1 & Public_Sector==1 & Union_Member_Status==1

*Midwest*
mean Democrat [pweight=weight] if White==1 & (State==19 | State==26 | State==27 | State==39 | State==42 | State==55) & Union_Member_Status==3
mean Democrat [pweight=weight] if White==1 & (State==19 | State==26 | State==27 | State==39 | State==42 | State==55) & Union_Member_Status==1

*South*
mean Democrat [pweight=weight] if White==1 & (State==12 | State==37 | State==51) & Union_Member_Status==3
mean Democrat [pweight=weight] if White==1 & (State==12 | State==37 | State==51) & Union_Member_Status==1

*West*
mean Democrat [pweight=weight] if White==1 & (State==4 | State==8 | State==32 | State==35) & Union_Member_Status==3
mean Democrat [pweight=weight] if White==1 & (State==4 | State==8 | State==32 | State==35) & Union_Member_Status==1

*Male, no college degree*
mean Democrat [pweight=weight] if White==1 & female==0 & college==0 & Union_Member_Status==3
mean Democrat [pweight=weight] if White==1 & female==0 & college==0 & Union_Member_Status==1
 
*Male, college degree* 
mean Democrat [pweight=weight] if White==1 & female==0 & college==1 & Union_Member_Status==3
mean Democrat [pweight=weight] if White==1 & female==0 & college==1 & Union_Member_Status==1

*Female, no college degree*
mean Democrat [pweight=weight] if White==1 & female==1 & college==0 & Union_Member_Status==3
mean Democrat [pweight=weight] if White==1 & female==1 & college==0 & Union_Member_Status==1

*Female, college degree* 
mean Democrat [pweight=weight] if White==1 & female==1 & college==1 & Union_Member_Status==3
mean Democrat [pweight=weight] if White==1 & female==1 & college==1 & Union_Member_Status==1 
































































